package com.hhw.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hhw.entity.Admin;
import com.hhw.service.AdminService;


/**
 * Servlet implementation class Doadminlogin
 */
@WebServlet("/doadminlogin")
public class Doadminlogin extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Doadminlogin() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	   
		//
		request.setCharacterEncoding("utf-8");
		String adminname =request.getParameter("adminname");
		String adminpassword = request.getParameter("adminpassword");
		String msg ="";
		
		Admin r = new Admin();
		r.setAdmin_name(adminname);
		r.setAdmin_password(adminpassword);
		System.out.println(adminname);
		System.out.println(adminpassword);
		
		//调用service进行管理员账号密码判断
		AdminService rs = new AdminService();
		
		if (rs.isExist(r)) {
			List<Admin> rlist = rs.findAdmin();
			request.setAttribute("rlist", rlist);
			System.out.println("登录成功！");
			request.getRequestDispatcher("tousermanage").forward(request, response);
		}else{
			System.out.println("账号或密码错误，请重新输入");
			request.getRequestDispatcher("toadminlogin").forward(request, response);
		}
	
		
		
	}

}
